﻿using System.IO;

namespace MLSharp.Utilities
{
	/// <summary>
	/// Contains extension methods for the <see cref="string"/> class.
	/// </summary>
	public static class StringExtensions
	{
		/// <summary>
		/// Appends a suffix to a filename.  The suffix is added
		/// before the last '.' in the filename.
		/// </summary>
		/// <param name="filename">The value to modify.</param>
		/// <param name="suffix">The suffix to add.</param>
		/// <returns>The modified filename.</returns>
		public static string AppendFilenameSuffix(this string filename, string suffix)
		{
			string directoryName = Path.GetDirectoryName(filename);

			string file = string.Format("{0}-{1}{2}", Path.GetFileNameWithoutExtension(filename),
			                                suffix,
			                                Path.GetExtension(filename));

			return Path.Combine(directoryName, file);
		}
	}
}
